package com.zed.api.useradmin;

import com.zed.api.common.collection.MemberCollection;

import java.util.Objects;

/**
 * 登录凭证集合
 *
 * @author Zed
 */
public interface LoginCertificates extends MemberCollection<LoginCertificate> {

    /**
     * 根据所属域域查找对应的登录凭证
     *
     * @param domain {@link String},所属域
     * @return {@link LoginCertificate},登录凭证可能为null
     */
    default LoginCertificate findByDomain(String domain) {
        return this.findByFilter(el -> Objects.equals(el.getDomain(), domain));
    }

    /**
     * 查找{@code id}对应的登录凭证
     *
     * @param id {@link String},主键
     * @return {@link LoginCertificate},登录凭证可能为null
     */
    LoginCertificate findById(String id);

    /**
     * 按{@code domain} 和 {@code identifier}查询登录凭证
     *
     * @param domain     {@link String},所属域
     * @param identifier {@link String},标识符
     * @return {@link LoginCertificate}
     */
    default LoginCertificate findByDomainAndIdentifier(String domain, String identifier) {
        return this.findByFilter(el -> Objects.equals(el.getDomain(), domain)
                && Objects.equals(el.getIdentifier(), identifier));
    }

}
